<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>


<?php echo form_tag_for($form, '@order') ?>
  <table id="order_form">
    <tbody>
      <?php 
      //shows the formulary ugly
//      echo $form 
      
      //with the edition options
//      echo $form->count();
      $i = 0;
      if ($form->hasErrors())
      {
        echo "errores :S";
      }
      while ($i < $form->getFormFieldSchema()->count()){
//        echo $form->getFormFieldSchema()->current()->__toString();
//        echo "b".$i;
        if($form->getFormFieldSchema()->current()->getName() == 'editionoptionsid')
        {
          $j = 0;
//          echo "2 ves?";
//          echo $form->getFormFieldSchema()->current()->getName();
//          echo $form->getFormFieldSchema()->current()->count();
//          $numberW = $form->getFormFieldSchema()->current()->count();
//          while($j < $numberW){
            echo $form->getFormFieldSchema()->current()->getWidget()->render('editionoptionsid');
//            echo $form->getFormFieldSchema()->current()->getWidget()->render("ownchoice");
//            $form->getFormFieldSchema()->next();
//            $j++;
//          }
//          echo "X".$i;//$form->getFormFieldSchema()->current()->__toString();
        }
        elseif(($form->getFormFieldSchema()->current()->getName() == 'othertextmediumid'))
        {
             echo $form->getFormFieldSchema()->current()->renderRow(); 
//           print_r("??");
//           print_r($form->getFormFieldSchema()->current()->__toString());//current()->getValue());
        }
        elseif(($form->getFormFieldSchema()->current()->getName() != '_csrf_token'))
        {
          if($form->getFormFieldSchema()->current()->getName() != 'idorder')
            {
            echo $form->getFormFieldSchema()->current()->renderRow();//->getName();
          }
            
        }
          
        
        $form->getFormFieldSchema()->next();

        $i++;
      }
      
      /*
      //new way
//      echo $form['text']->renderRow();
      $i = 0;
//      echo $form->getFormFieldSchema()->count();
//      while ($i < $form->getFormFieldSchema()->count()){
//        echo $form->getFormFieldSchema()->current()->__toString();
//      }
//      $i = 1;
//      $r = new OwnchoiceForm();
//      echo $r->getFormFieldSchema();
//      echo $form[]->['ownchoice[0]']->renderRow();
      foreach ($form['Own choice form'] as $editionOptions)
      {
        foreach ($editionOptions as $j => $clientOrder){
//          echo $j." -- ";//[$j]->renderRow();
          if($j == "edition options form"){
            foreach ($clientOrder as $order){
              echo $order;
            }
          }
          
//            echo $clientOrder['Order name']->renderRow();
        }
        
        echo $editionOptions['is_superlative']->renderRow();
        echo $editionOptions['is_technical_terms']->renderRow();
        echo $editionOptions['is_foraign_word']->renderRow();
        echo $editionOptions['is_old_language']->renderRow();
        echo $editionOptions['is_start_of_sentence']->renderRow();
        
//        foreach ($editionOptions as $j => $clientOrder){
            //if($j != "edition options form"){
//              echo $editionOptions['is_superlative']->renderRow();//[$j]->renderRow();
//            }
//        }
 
      } 
      echo $form['text']->renderRow();
       
       */
      ?>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="2">
          &nbsp;<a href="<?php echo url_for('order/index') ?>">Back to list</a>
          <?php if (!$form->getObject()->isNew()): ?>
            &nbsp;<?php echo link_to('Delete', 'order/delete?idorder=' . $form->getObject()->getIdorder(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
          <?php endif; 
//          echo $form->getFormFieldSchema()->__toString();
          ?>
          <input type="submit" value="Preview your order" />
        </td>
      </tr>
    </tfoot>
  </table>
</form>
